package com.itheima.controller;

import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.entity.Student;
import com.itheima.entity.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/students")
    public Result page(StudentQueryParam param){
        PageBean pageBean=studentService.page(param);
        return Result.success(pageBean);
    }

    @DeleteMapping("/students/{ids}")
    public Result delete(@PathVariable("ids") List<Integer> ids){

        studentService.delete(ids);

        return Result.success();
    }

    @PostMapping("/students")
    public Result insert(@RequestBody Student student){
        studentService.insert(student);
        return Result.success();
    }

    @GetMapping("/students/{id}")
    public Result getById(@PathVariable Integer id){
        Student studentById=studentService.getById(id);
        return Result.success(studentById);
    }

    @PutMapping("/students")
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }

    @PutMapping("students/violation/{id}/{score}")
    public Result updateV(@PathVariable Integer id,@PathVariable Integer score){
        studentService.updateV(id,score);
        return Result.success();
    }

}
